const mongoose = require("mongoose");

// 订单列表
const getorder=async({ curPage, eachPage })=>{
    // return await mongoose.model("orders").find();
    const result = {
        curPage: Number(curPage),
        eachPage: Number(eachPage),
        // 总条数
        total: 0,
        // 总页数
        maxPage: 0,
        rows: []
    
      };
      const orersModel = mongoose.model("order");
      //    获取总条数
      result.total = await orersModel.countDocuments();
      result.maxPage = Math.ceil(result.total / result.eachPage);
      //   操作类型  填充 忽略条数
      result.rows = await orersModel.find()
        .skip((result.curPage - 1) * result.eachPage)
        .limit(result.eachPage)
        .sort({
          _id: -1
        })
        //   执行
        .exec();
      return result;
}

// 根据电影名查订单
const searchMove=async(moveName)=>{
    return await mongoose.model("order").find({moveName});
  }

  // 获取拍片下所有座位
const getseating=async(schedules)=>{
  return await mongoose.model("seating").find({schedules})
}
// 查找座位改变状态
const changeseating=async(_id,status)=>{
  return await mongoose.model("seating").updateOne({_id:_id},{status:status});
}

// 查找某一个座位
const getseatingOne=async(_id)=>{
return await mongoose.model("seating").findOne({_id});
}

// 新增订单
const addorder=async(orderdata)=>{
  return await mongoose.model("order").create(orderdata);
}



  module.exports = {addorder,getorder,getseating,changeseating,getseatingOne,searchMove};